package com.polaris.live.viewmodel.backpack

import androidx.lifecycle.MutableLiveData
import com.polaris.live.common.mvvm.viewmodel.BaseViewModel
import com.polaris.live.common.network.request
import com.polaris.live.common.network.requestLoading
import com.polaris.live.common.network.state.ResultState
import com.polaris.live.resp.back_resp.UserBackpackDecorationResp
import com.polaris.live.net.userService
import com.polaris.live.resp.go_resp.BackPackRedRequest
import com.polaris.live.resp.go_resp.UseDressUpBean
import com.polaris.live.resp.go_resp.UseDressUpResp

/**
 * BackPackViewModel 背包Model
 *
 * @author Created by 天晴 on 2024/1/17 9:15
 * @since 1.0.0
 **/
class BackPackViewModel : BaseViewModel() {

    //背包数据请求
    val mBackpackLiveData = MutableLiveData<ResultState<List<UserBackpackDecorationResp>>>()
    fun getBackpackByType(decorationType: Int) {
        request({ userService.getUserBackpackByType(decorationType, 0) }, mBackpackLiveData)
    }

    //使用装饰
    val mUseSuccessLiveData = MutableLiveData<UseDressUpResp>()
    fun useDressUp(
        backpackId: Long,
        useStatus: Int,
        userBack: UserBackpackDecorationResp,
        position: Int,
    ) {
        val useDressUp = UseDressUpBean(backpackId, useStatus)
        val useResp = UseDressUpResp(backpackId, useStatus, userBack, position)
        requestLoading({ userService.useDressUp(useDressUp) }, {
            mUseSuccessLiveData.value = useResp
        }, waitTime = 0)
    }

    val mPutBackpackNewLiveData = MutableLiveData<ResultState<Any>>()

    /**
     * 通知后台更新背包红点
     */
    fun putBackpackNew(backpackType: Long, decorationType: Long? = null) {
        request(
            { userService.putBackpackNew(BackPackRedRequest(backpackType, decorationType)) },
            mPutBackpackNewLiveData
        )
    }
}